@model OrchardCore.ContentFields.ViewModels.EditHtmlFieldViewModel

@{
    var settings = Model.PartFieldDefinition.GetSettings<HtmlFieldSettings>();
    var culture = await Orchard.GetContentCultureAsync(Model.Field.ContentItem);
}

<script name="trumbowyg" depends-on="admin" asp-src="~/OrchardCore.Resources/Scripts/trumbowyg.min.js" debug-src="~/OrchardCore.Resources/Scripts/trumbowyg.js" at="Foot"></script>
<style name="trumbowyg" asp-src="~/OrchardCore.Resources/Styles/trumbowyg.min.css" debug-src="~/OrchardCore.Resources/Styles/trumbowyg.css"></style>

<fieldset class="form-group">
    <label asp-for="Html">@Model.PartFieldDefinition.DisplayName()</label>
    @if (culture.IsRightToLeft())
    {
        <div style="text-align:right">
            <textarea asp-for="Html" class="form-control"></textarea>
        </div>
    }
    else
    {
        <textarea asp-for="Html" class="form-control"></textarea>
    }

    @if (!String.IsNullOrEmpty(settings.Hint))
    {
        <span class="hint">@settings.Hint</span>
    }
</fieldset>

<script at="Foot">
    $(function () {
        $('#@Html.IdFor(m => m.Html)').trumbowyg().on('tbwchange', function () {
            $(document).trigger('contentpreview:render');
        });
    });
</script>